import nltk
from nltk.corpus import brown
from nltk.collocations import BigramAssocMeasures, BigramCollocationFinder

# 下载Brown语料库（如果尚未下载）
nltk.download('brown')

# 定义目标词汇和其不同词性
target_word = "play"
word_pos_tags = ["VB", "NN", "JJ"]  # 动词、名词、形容词

# 创建一个语料库
corpus = brown.words()

# 过滤出包含目标词汇及其不同词性的搭配
finder = BigramCollocationFinder.from_words(corpus)
finder.apply_word_filter(lambda w: w.lower() != target_word.lower())
finder.apply_word_filter(lambda w: nltk.pos_tag([w])[0][1] not in word_pos_tags)

# 计算搭配的频率
bigram_measures = BigramAssocMeasures()
collocations = finder.nbest(bigram_measures.raw_freq, 10)  # 获取前10个最常见的搭配

# 输出结果
for collocation in collocations:
    print(" ".join(collocation))
